import langchain
import openai
from langchain_core.messages import SystemMessage,HumanMessage
from langchain_openai import ChatOpenAI
from langchain_community.chat_models import ChatBaichuan
from langchain_core.prompts import ChatPromptTemplate,FewShotChatMessagePromptTemplate

openai.api_key = "sk-6S0PtpNia71gjcfwSsDPsJ9mGqsVPr2XRQzAx1dHbJS7RW4t"
openai.api_base="https://chatapi.littlewheat.com/v1"

print(langchain.__version__)

#messages = [SystemMessage(content="你是一位乐于助人的智能小助手"),HumanMessage(content="你好，请你介绍一下你自己")]
chat = ChatOpenAI(model="gpt-3.5-turbo",api_key=openai.api_key ,base_url=openai.api_base)
#print(chat.invoke(messages).content)
#for chunk in chat.stream(messages):
 #   print(chunk.content,end="",flush=True)
#response = chat.invoke([("human", "请介绍一下你自己")])
#print(response.content)

chat_template = ChatPromptTemplate.from_messages(
[
        ("system", "你是一个有帮助的AI机器人，你的名字是{name}。"),
        ("human", "你好，最近怎么样？"),
        ("ai", "我很好，谢谢！"),
        ("human", "{user_input}"),
    ]
)
messages=chat_template.format_messages(name="小米",user_input="你叫什么名字?")
response = chat.invoke(messages)
print(response.content)
FewShotChatMessagePromptTemplate()

